package com.ruoyi.management.service.impl;

import java.math.BigDecimal;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.management.domain.CommissionManagementDetail;
import com.ruoyi.management.mapper.CommissionManagementDetailMapper;
import com.ruoyi.management.service.ICommissionManagementDetailService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.basic.service.impl.BaseServiceImpl;

/**
 * 佣金明细Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-17
 */
@Service
public class CommissionManagementDetailServiceImpl extends 
	BaseServiceImpl<Long, CommissionManagementDetail> implements ICommissionManagementDetailService 
{
    public CommissionManagementDetailServiceImpl(CommissionManagementDetailMapper baseMapper) {
		super(baseMapper);
		// TODO Auto-generated constructor stub
	}
    /**
     * 查询佣金明细
     * 
     * @param id 佣金明细主键
     * @return 佣金明细
     */
    @Override
    public CommissionManagementDetail selectById(Integer id)
    {
        return baseMapper.selectById(id);
    }

    /**
     * 查询佣金明细列表
     * 
     * @param commissionManagementDetail 佣金明细
     * @return 佣金明细
     */
    @Override
    public List<CommissionManagementDetail> selectList(CommissionManagementDetail commissionManagementDetail)
    {
        return baseMapper.selectList(commissionManagementDetail);
    }

    /**
     * 新增佣金明细
     * 
     * @param commissionManagementDetail 佣金明细
     * @return 结果
     */
    @Override
    public int insert(CommissionManagementDetail commissionManagementDetail)
    {
        return baseMapper.insert(commissionManagementDetail);
    }
    
    @Override
    public CommissionManagementDetail generate(int commissionId, BigDecimal amount, int userId) {
    	
    	CommissionManagementDetail commissionManagementDetail = new CommissionManagementDetail();
    	
    	commissionManagementDetail.setCommissionId(commissionId);
    	
    	commissionManagementDetail.setDescription("佣金提现");
    	
    	commissionManagementDetail.setMonry(amount);
    	
    	commissionManagementDetail.setType(0);
    	
    	commissionManagementDetail.setUserId(userId);
    	
    	insertProperties(commissionManagementDetail);
		return commissionManagementDetail;
    }
    

    /**
     * 修改佣金明细
     * 
     * @param commissionManagementDetail 佣金明细
     * @return 结果
     */
    @Override
    public int update(CommissionManagementDetail commissionManagementDetail)
    {
        return baseMapper.update(commissionManagementDetail);
    }

    /**
     * 批量删除佣金明细
     * 
     * @param ids 需要删除的佣金明细主键
     * @return 结果
     */
    @Override
    public int deleteByIds(Integer[] ids)
    {
        return baseMapper.deleteByIds(ids);
    }

    /**
     * 删除佣金明细信息
     * 
     * @param id 佣金明细主键
     * @return 结果
     */
    @Override
    public int deleteById(Integer id)
    {
        return baseMapper.deleteById(id);
    }
    
    
	@Override
	public int countByRecommendUser(int userId, int commissonManagentId) {
		
		CommissionManagementDetailMapper managementDetailMapper = this.getBaseMapper();
		
		return managementDetailMapper.countByRecommendUser(userId, commissonManagentId);
	}
}
